<!-- left column -->

    <div class="box">
        <div class="box-header solist pd-top0">
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs pull-left" style="cursor: move;" id="myTab">
                    <li class="<?php if(0 == $search['type']){?> active <?php }?>" material_type='0'>
                        <a href="javascript:;" data-toggle="tab">图片素材</a></li>
                    <li class="<?php if(1 == $search['type']){?> active <?php }?>" material_type='1'>
                        <a href="javascript:;">视频素材</a></li>
                </ul>
            </div>
        </div>
        <div class="box-body solist">
            <div class="box-form form-inline" id='SearchForm'>
                <a href="javascript:;" class="btn btn-primary bg-pink btn-big" id='createBtn'>
                    <?php if(0 == $search['type']){?>
                        添加图片
                    <?php }else{?>
                        添加视频
                    <?php }?>
                </a>

                <div class="form-group">
                    <label>素材名称:</label>
                    <input type="text" class="form-control" name="name" style='width:150px;'
                    value="<?php echo (isset($search['name'])?$search['name']:'') ?>">
                </div>

                <?php if('yes' != $is_admin){?>
                    <div class="form-group">
                        <label><?=$is_start_label ?>:</label>
                        <select name="status" style='width:150px;' class='form-control'>
                            <option value="">请选择</option>
                            <?php
                            foreach ($is_start_opts as $key => $opts) {
                            ?>
                                <option value="<?=$opts['opts_key'] ?>" <?php if(isset($search['status']) && $search['status'] == $opts['opts_key']) echo 'selected';?>><?=$opts['opts_val'] ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                <?php }else{?>
                    <div class="form-group">
                        <label>品牌:</label>
                        <select name="brand_id" style='width:150px;' class='form-control'>
                            <option value="">请选择</option>
                            <?php
                            foreach ($brand_opts as $key => $opts) {
                            ?>
                                <option value="<?=$opts['id'] ?>" <?php if(isset($search['brand_id']) && $search['brand_id'] == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                <?php }?>
                <div class="form-group">
                    <label></label>
                    <select name="brandinfo_id" style='width:180px;' class="form-control">
                        <option value="">请选择素材版块名称</option>
                        <?php
                        foreach ($brandinfo_opts as $key => $opts) {
                        ?>
                            <option value="<?=$opts['id'] ?>" <?php if(isset($search['brandinfo_id']) && $search['brandinfo_id'] == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                        <?php
                        }
                        ?>
                    </select>
                </div>
                <button type="button" class="btn btn-default" id='searchBtn'>搜索</button>
                <a class="btn btn-default btn-big pull-right" id='updateGroup'>移动分组</a>
            </div>
            <table class="table table-bordered text-center" id='ListTab'>
                <thead>
                    <tr>
                        <th><input type="checkbox" class="market-check-all" id='allselected'></th>
                        <th nowrap>素材名称</th>
                        <th nowrap>板块</th>
                        <th nowrap>标签</th>
                        <?php if('yes' == $is_admin){?>
                            <th nowrap>品牌</th>
                        <?php }?>
                        <th nowrap>是否启用</th>
                        <th nowrap>创建时间</th>
                        <th nowrap>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach ($materialList as $key=>$material) {
                    ?>
                        <tr style='text-align: center;'>
                            <td><input type="checkbox" class="market-check" value="<?= $material['id']?>"></td>
                            <td><a href='<?= $material['url']?>' target="_blank"><?= $material['name']?></a></td>
                            <td><?= $material['brandinfo_name']?></td>
                            <td><?= $material['tagname']?></td>
                            <?php if('yes' == $is_admin){?>
                                <th><?= $material['brand_name']?></th>
                            <?php }?>
                            <td>
                                <?php if(1 == $material['status']){?>
                                    是
                                <?php }else{?>
                                    否
                                <?php }?>
                            </td>
                            <td><?= $material['update_time']?></td>
                            <td nowrap>
                                <!-- <a class="btn btn-default btn-xs btn-flat margin" href='<?=base_url()?>index.php/admin/material/show/<?= $material['id']?>' tag='edit_link'>查看</a> -->
                                <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' tag='enable_link'
                                                byid="<?= $material['id']?>" status="<?=$material['status']?>" >
                                    <?php if(1 == $material['status']){?>
                                        禁用
                                    <?php }else{?>
                                        启用
                                    <?php }?>
                                </a>
                                <?php if('yes' == $is_admin){?>
                                    <a class="btn btn-default btn-xs btn-flat margin" href='javascript:;' byid="<?= $material['id']?>" tag='delete_link'>删除</a>
                                <?php }?>
                            </td>
                        </tr>
                    <?php
                    }
                    ?>
                    <tr>
                        <td colspan="9" style='text-align: right;display: none;'>
                            <span style='word-spacing:8px; letter-spacing: 10px;' id='paginate'>
                                <?=$paginate?>
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- /.box-body -->
        <div class="box-footer clearfix">
            <ul class="pagination pagination-sm no-margin pull-right" id='paginateul'></ul>
            <span class='no-margin pull-right' style='padding-right:40px;'><?=$pagetitle?></span>
        </div>
    </div>

<!--/.col (left) -->
<!-- ./wrapper -->
<div class="modal modalDel confirmDialog" id="delModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="confirm-icon">
                    <i class="fa fa-exclamation-circle"></i>
                </div>
                <div class="confirm-text">
                    <h4>删除确认！</h4>
                    <p>删除后将无法恢复！是否确定要删除?</p>
                </div>
            </div>
            <div class="modal-footer" style="text-align:center !important">
                <button type="button" class="btn btn-primary btn-big bg-pink btnYes">确认</button>
                <button type="button" class="btn btn-default btn-big" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <form class="form-horizontal" role="form">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">
                        移动分组
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">移动至</label>
                        <div class="col-sm-6">
                            <select class="form-control" id='updateGroupSelt'>
                                <option value=""></option>
                                <?php
                                foreach ($brandinfo_opts as $key => $opts) {
                                ?>
                                    <option value="<?=$opts['id'] ?>"><?=$opts['name'] ?></option>
                                <?php
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-big" id='updateGroupBtn'>
                        确定
                    </button>
                    <button type="button" class="btn btn-default btn-big" data-dismiss="modal" id='updateGroupCancelBtn'>取消
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div>
</div><!-- /.modal -->

<script src="<?= base_url()?>style/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="<?= base_url()?>style/bootstrap/js/bootstrap.min.js"></script>
<script src="<?= base_url()?>style/dist/js/app.min.js"></script>
<!-- <script src="../dist/js/demo.js"></script> -->

<script type="text/javascript">
  var pageMenu = {"active": [2]};
  // $(function() {
  //   //全选
  //   $("input.market-check-all").on("change",function(){
  //       if(!!$(this).prop("checked")){
  //           $("input.market-check").prop("checked", true);
  //       }
  //       else {
  //           $("input.market-check").prop("checked", false);
  //       }
  //   });
  //   $("input.market-check").on("change",function(){
  //       var length1=$("input.market-check").length;
  //       var length2=$("input.market-check:checked").length;
  //       if(length1==length2){
  //           $("input.market-check-all").prop("checked",true);
  //       }else{
  //           $("input.market-check-all").prop("checked",false);
  //       }
  //   });
  // })
$(function(){
    var is_submit = 1;
    var cur_page = "<?=$cur_page?>";
    $('a[tag=delete_link]').on('click',function(){
        if(confirm('确定要删除吗？')){
            $.get('<?=base_url()?>index.php/admin/<?= $module?>/destroy/'+$(this).attr('byid'),function(rest){
                if($('#ListTab > tbody > tr').length == 2 && cur_page > 1){
                    $('#searchBtn').attr('cur_page',(cur_page-1));
                    $('#searchBtn').click();
                }else{
                    $('#searchBtn').attr('cur_page',cur_page);
                    $('#searchBtn').click();
                }
            });
        }
        return false;
    });
    //上下架
    $('a[tag=enable_link').on('click',function(){
        var param = {};
        param['status'] = $(this).attr('status');
        $.get('<?=base_url()?>index.php/admin/<?= $module?>/enable/'+$(this).attr('byid'),param,function(rest){
            $('#searchBtn').attr('cur_page',cur_page);
            $('#searchBtn').click();
        });
    });
    $('#createBtn').on('click',function (){
        var material_type = $('#myTab li.active').attr('material_type');
        location.href = base_url+'index.php/admin/<?= $module?>/create?material_type='+material_type;
    });
    $('#searchBtn').on('click',function(){
        var param = {};
        $('#SearchForm input[name],select[name]').each(function(){
            if($(this).val() != ''){
                param[$(this).attr('name')] = $(this).val();
            }
        });
        if($(this).attr('cur_page') > 0){
            param['cur_page'] = $(this).attr('cur_page');
        }else{
            param['cur_page'] = 1;
        }
        $(this).attr('cur_page',0);
        param['type'] = $('#myTab li.active').attr('material_type');
        searchList(param);
    });
    $('#SearchForm input[name]').on({
        'keypress':function (event){
            var e = window.event||event;
            if(13 == e.keyCode){
                $('#searchBtn').click();
            }
        }
    });
    //将ci的分页放到新的版本中去
    if($('#paginate a').length > 0){
        var paginateul = '';var link_href = '';var link_val = '';
        $('#paginate a,strong').each(function (){
            link_val = $(this).html();
            link_href = $(this).attr('href');
            if(link_href != undefined){
                if('Last ›' == link_val){
                    link_val = '>>';
                }else if('‹ First' == link_val){
                    link_val = '<<';
                }
                paginateul += '<li><a href="'+link_href+'">'+link_val+'</a></li>';
            }else{
                paginateul += '<li><a href="#" onclick="return false;" style="color:#428bca;"><b>'+link_val+'</b></a></li>';
            }
        });
        $('#paginateul').html(paginateul);
        //绑定分页事件
        $('#paginateul').on('click','a[href]',function(){
            var url = $(this).attr('href');
            if('#' == url) return false;
            var urlarr = url.split('=');
            var cur_page = urlarr[urlarr.length-1];
            if(isNaN(cur_page)) cur_page = 1;
            var param = {};
            $('#SearchForm input[name],select[name]').each(function(){
                if($(this).val() != ''){
                    param[$(this).attr('name')] = $(this).val();
                }
            });
            param['cur_page'] = parseInt(cur_page);
            param['type'] = $('#myTab li.active').attr('material_type');
            searchList(param);
            return false;
        });
    }
    //tab标签页事件绑定
    $('#myTab li').on('click',function(){
        $(this).parent().find('li').attr('class','');
        $(this).attr('class','active');
        $('#createBtn').html('添加'+$(this).find('a').html().substring(0,2));
        var param = {};
        $('#SearchForm input[name],select[name]').each(function(){
            if($(this).val() != ''){
                param[$(this).attr('name')] = $(this).val();
            }
        });
        param['cur_page'] = 1;
        param['type'] = $(this).attr('material_type');
        searchList(param);
        return false;
    });
    $('#allselected').on('click',function(){
        $('#ListTab tbody input[type=checkbox].market-check').prop('checked',$(this).prop('checked'));
    });
    $('#updateGroup').on('click',function (){
        if(0 == $('#ListTab tbody input[type=checkbox]:checked').length){
            alert('请选择素材。');
            return false;
        }
        $("#myModal").modal("show");
    });
    $('#updateGroupBtn').on('click',function(){
        var updateGroupSelt = $('#updateGroupSelt').val();
        if(updateGroupSelt == ''){
            alert('请选择板块。');
            return false;
        }
        var material_id = '';
        $('#ListTab tbody input[type=checkbox]:checked').each(function(){
            if(material_id == ''){
                material_id = $(this).val();
            }else{
                material_id += ','+$(this).val();
            }
        });
        var param = {};
        param['brandinfo_id'] = updateGroupSelt;
        param['material_id'] = material_id;
        $.post('<?=base_url()?>index.php/admin/material/updateGroup',param,function(rest){
            $('#myModal').modal("hide");
            $(".modal-backdrop").remove();
            $('#searchBtn').click();
        });
    });
});
</script>
<script src="<?= base_url()?>style/js/vendors.js" type="text/javascript"></script>
<script src="<?= base_url()?>style/js/index.js" type="text/javascript"></script>

</body>
</html>
